<template>
  <div class="mod-config" v-loading="submitLoading"  :element-loading-text="'正在提交'" >
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">

      <el-form-item   >
        <el-select v-model="dataForm.djzx" placeholder="登记中心" style="width:100%" clearable>
                <el-option
              v-for="item in dataForm.bankList"
              :key="item.bankid"
              :label="item.bankname"
              :value="item.bankid">
            </el-option>
        </el-select>
      </el-form-item>  

      <el-form-item>
        <el-date-picker
          v-model="dataForm.begindate"
          type="datetime"
          placeholder="选择起始时间"
          align="right"
          default-time="00:00:00"
          :picker-options="pickerOptions">
        </el-date-picker>
      </el-form-item>   

      <el-form-item>
        <el-date-picker
          v-model="dataForm.enddate"
          type="datetime"
          placeholder="选择结束时间"
          default-time="23:59:59"
          align="right"
          :picker-options="pickerOptions">
        </el-date-picker>
      </el-form-item>


      <el-form-item>
        <el-button type="primary"  @click="getDataList()">本地查询</el-button>
        <el-button v-if="isAuth('bdc:bdcrecordimage:save')" type="primary" @click="addOrUpdateHandle()">新增</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">

      <el-table-column
        prop="recordtime"
        header-align="center"
        align="center"
        width="160px"
        label="影像备案时间">
      </el-table-column>
      <el-table-column
        prop="bdcno"
        header-align="center"
        align="center"
        width="130px"
        label="登记中心">
      </el-table-column>
            <el-table-column
        prop="dyqr"
        header-align="center"
        align="center"
        width="130px"
        :show-overflow-tooltip="true"
        label="抵押权人">
      </el-table-column>

    <el-table-column
        prop="ftype"
        header-align="center"
        align="center"
        width="130px"
        label="备案类型">
      </el-table-column>

      <el-table-column
        prop="obankid"
        header-align="center"
        align="center"
         width="130px"
        label="发起网点">
      </el-table-column>
      <el-table-column
        prop="yxbsm"
        header-align="center"
         width="180px"
        align="center"
        label="备案标识码">
      </el-table-column>

      <el-table-column
        prop="name"
        header-align="center"
         width="180px"
        align="center"
        label="经办人姓名">
      </el-table-column>

      <el-table-column
        prop="idcode"
        header-align="center"
         width="180px"
        align="center"
        label="经办人证件号码">
      </el-table-column>

      <el-table-column
        prop="phone"
        header-align="center"
         width="180px"
        align="center"
        label="经办人手机号">
      </el-table-column>

      <el-table-column
        prop="enabledate"
        header-align="center"
        align="center"
         width="160px"
        label="生效日期">
      </el-table-column>
      <el-table-column
        prop="disabledate"
        header-align="center"
        align="center"
        width="160px"
        label="截止日期">
      </el-table-column>
      <el-table-column
        prop="content"
        header-align="center"
        align="center"
        width="160px"
        label="影像备注说明">
      </el-table-column>

      <el-table-column
        prop="region"
        header-align="center"
        align="center"
        label="区域">
      </el-table-column>

      <el-table-column
        prop="state"
        width="160px"
        header-align="center"
        align="center"
        :show-overflow-tooltip="true"
        label="状态">
      </el-table-column>
      <el-table-column
        prop="descinfo"
        header-align="center"
        align="center"
        width="160px"
        :show-overflow-tooltip="true"
        label="状态描述">
      </el-table-column>

      <el-table-column
        fixed="left"
        header-align="center"
        align="center"
        width="150"
        label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="cancelBaHandle(scope.row.seqno)" v-if="scope.row.content != '影像材料备案注销'" >备案注销</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="datepicker.pageOptions"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  </div>
</template>

<script>
  import AddOrUpdate from './bdcrecordimage-add-or-update'
  export default {
    data () {
      return {
        pickerOptions: this.datepicker.pickerOptions,
        dataForm: {
          begindate: '',
          enddate: '',
          bankList: [],
          djzx: ''
        },
        submitLoading: false,
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        addOrUpdateVisible: false
      }
    },
    components: {
      AddOrUpdate
    },
    activated () {
      this.init()
      this.getDataList()
    },
    methods: {

      init(){

        this.$http({
          url: this.$http.adornUrl(`/bdc/bdcrecordimage/condition/item`),
              method: 'get',
              params: this.$http.adornParams()
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.dataForm.bankList = data.djzxList
            }
        })

      },

      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl('/bdc/bdcrecordimage/list'),
          method: 'get',
          params: this.$http.adornParams({
            'page': this.pageIndex,
            'limit': this.pageSize,
            'begindate': this.dataForm.begindate,
            'enddate': this.dataForm.enddate,
            'djzx': this.dataForm.djzx
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.dataList = data.page.list
            this.totalPage = data.page.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },
      cancelBaHandle(seqno){
            this.submitLoading = true
            this.$http({
              url: this.$http.adornUrl(`/bdc/bdcrecordimage/send0009C/` + seqno),
              method: 'post',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '影像材料注销备案成功',
                  type: 'success',
                  duration: 1500
                })  
                this.getDataList()        
              }else{
                this.$message.error(data.msg);
              }
              this.submitLoading = false
            }).catch(err => {
              this.submitLoading = false;
              console.error(err);
              this.$message.error('系统异常')              
            }); 
      },
      // 新增 / 修改
      addOrUpdateHandle (id) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(id)
        })
      },
      // 删除
      deleteHandle (id) {
        var ids = id ? [id] : this.dataListSelections.map(item => {
          return item.seqno
        })
        this.$confirm(`确定对[id=${ids.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl('/bdc/bdcrecordimage/delete'),
            method: 'post',
            data: this.$http.adornData(ids, false)
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.getDataList()
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        })
      }
    }
  }
</script>
<style lang="scss">
body .el-table th.gutter{
    display: table-cell!important;

}
</style>